sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
12.28k stars 777 forks source link

No result when specifying created_at and/or updated_at columns #2323

Closed dbhiiper closed 11 months ago

dbhiiper commented 1 year ago

Version

1.18.0

What happened?

I get no results when using created_at or updated_at columns in SELECT statement. If i leave out the two columns then i get the expected results. I've run the query including created_at and updated_at using DBeaver and it works correctly.

Relevant log output

No response

Database schema

CREATE TABLE jobs (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    template_id BIGINT NOT NULL,
    status INT NOT NULL DEFAULT 1,
    report json,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (template_id) REFERENCES job_templates(id)
);

SQL queries

-- name: ListJobs :many
SELECT
    j.id,
    j.status,
    j.created_at,
    j.updated_at,
    jt.external_ref,
    jt.url,
    jt.job_schema,
    p.common_name as provider_name
FROM
    jobs j
    INNER JOIN job_templates jt ON j.template_id = jt.id
    INNER JOIN providers p ON jt.provider_id = p.id
WHERE
    j.status = ?;

Configuration

version: "1"
packages:
- name: "mysql"
  path: "."
  queries: "./query/"
  schema: "../../db/migrations/"
  engine: "mysql"
  emit_json_tags: false
  emit_db_tags: false
  emit_prepared_queries: false
  emit_interface: false
  emit_exact_table_names: true
  emit_empty_slices: true

Playground URL

https://play.sqlc.dev/p/383409dd75455f035516b8b5a44074ba4c8c06d46ba1149402d1817921364b09

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

kyleconroy commented 1 year ago

I'm not able to reproduce this behavior. I added your query to the playground and I'm seeing the created_at and updated_at values being scanned correctly.