porsager / porsager/postgres

Custom types with dynamic columns in select statement

Open
#1,010 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

I am currently doing something like this (https://github.com/porsager/postgres?tab=readme-ov-file#dynamic-column-selection) and is seeing the same issue mentioned in #161. I added https://github.com/porsager/postgres?tab=readme-ov-file#custom-types but can't see how I can make it work with my select statement as the columns are in an array.

Does anyone have a sample piece of code that they have working to get the timestamp as a string using dynamic column in a select statement? Here is a simple example of what I'm trying to do:

var cols = ['id', 'name', 'last_created'];
var result = sql`select ${sql(cols)} from members`;

/* expecting: 
[ 
	{ 
		id: 1, 
		name: "john", 
		last_created: "2023-09-11T00:00:00.000Z"
	}
] 
*/

Thank you in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dynamic column selection and custom types examples linked in the issue, then compare them with the provided query using the cols array. Determine whether the documented combination supports the expected timestamp string output; done means a confirmed working example or a clearly documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.